﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using blackhouse.BlackApart.Data;
using System.Globalization;
using blackhouse.Currencies;

namespace blackhouse.BlackApart.Business.Company {
	public class DaCompany : ICompany {

		#region Fields

		private ICompanyDataAccess dataAccess;
		private ImpCompany instance;

		#endregion

		#region Constructors

		public DaCompany(ICompanyDataAccess data) {
			this.dataAccess = data;
			this.instance = new ImpCompany();
		}

		#endregion

		#region Methods

		public CompanyCounts GetCounts() {
			if (this.instance.Counts == null) {
				CompanyCountsData data = this.dataAccess.GetCompanyCounts();
				this.instance.Counts = new CompanyCounts(data);
			}
			return this.instance.Counts;
		}

		public ApartmentPromotionBaner[] GetBanners() {
			if (this.instance.Banners == null) {
				ApartmentPromotionBanerData[] data = this.dataAccess.GetBanners(CultureInfo.CurrentCulture.Name);
				this.instance.Banners = data.Select(d => new ApartmentPromotionBaner(d)).ToArray();
			}
			return this.instance.Banners;
		}

		public Currency GetCurrentUserCurrency() {
			return this.GetCurrentUserCurrency(1);
		}

		public Currency GetCurrentUserCurrency(double withValue) {
			if (this.instance.Languages == null) {
				LanguageData[] data = this.dataAccess.GetLanguages();
				this.instance.Languages = data.Select(d => new CompanyLanguage(d)).ToArray();
			}
			return this.instance.GetCurrentUserCurrency(withValue);
		}

		#endregion

	}
}
